﻿Imports EVOLTA.Promocion.Bl.Bc
Imports EVOLTA.Promocion.Bl.Be
Imports System.Data.SqlClient
Imports System.Data

Partial Class reportes_consultaEstadoTechoPropio
    Inherits System.Web.UI.Page

    Private separaciones As List(Of EseparacionVenta) = Nothing
    Private separacionesDetalle As List(Of EseparacionVentaDetallePagos)

#Region "       Formulario                          "
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Response.CacheControl = "no-cache"
        Response.AddHeader("Pragma", "no-cache")
        Response.Expires = -1
    End Sub
    Protected Sub btnBuscar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnBuscar.Click
        If txtFchInicio.Text.Length > 0 AndAlso txtFchFin.Text.Length > 0 Then
            Dim venta As New EseparacionVenta
            With venta
                .fchInicio = txtFchInicio.Text
                .fchFin = txtFchFin.Text
            End With
            separaciones = RseparacionVenta.ReporteEstadoTP(Me.Master.descEmpresa, venta)

            Session("separacionesLista") = separaciones
            If Not separaciones Is Nothing Then
                egvSeparacionVenta.DataSource = separaciones
                egvSeparacionVenta.DataBind()
                upnSeparacionVenta.Update()
                lblCantidadTotalSeparación.Text = String.Format(": {0}", separaciones.Count.ToString)
            End If
        End If
    End Sub
    Protected Sub btnLimpiar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLimpiar.Click
        txtFchInicio.Text = ""
        upFchInicio.Update()
        txtFchFin.Text = ""
        upFchFin.Update()
        egvSeparacionVenta.DataSource = Nothing
        upnSeparacionVenta.Update()
    End Sub
    Protected Sub btnExportar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExportar.Click
        Dim separacionVenta As New EseparacionVenta
        Dim comillas As String = Char.ConvertFromUtf32(34)
        With separacionVenta
            .fchInicio = txtFchInicio.Text
            .fchFin = txtFchFin.Text
        End With
        separaciones = RseparacionVenta.ReporteEstadoTP(Me.Master.descEmpresa, separacionVenta)
        Session("separacionLista") = separaciones

        Dim fileName As String = "ConsultaEstadoTP{0}.xls"
        fileName = String.Format(fileName, DateTime.Now.ToShortDateString())
        Dim Response As HttpResponse = HttpContext.Current.Response
        Response.ContentType = "application/vnd.ms-excel"
        Response.Charset = "UTF-8"
        Response.ContentEncoding = System.Text.Encoding.Default
        Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName)

        Response.Write("Proyecto") : Response.Write(vbTab)
        Response.Write("Etapa") : Response.Write(vbTab)
        Response.Write("Fecha TP") : Response.Write(vbTab)
        Response.Write("Tipo") : Response.Write(vbTab)
        Response.Write("Nombre Ciente") : Response.Write(vbTab)
        Response.Write("Monto TP") : Response.Write(vbTab)
        Response.Write("Estado") : Response.Write(vbTab)
        Response.Write(vbCrLf)
        Dim value As String

        For Each trx In separaciones
            value = trx.descProyecto : Response.Write(value) : Response.Write(vbTab)
            value = trx.descEtapa : Response.Write(value) : Response.Write(vbTab)
            value = trx.FechaTechoPropio : Response.Write(value) : Response.Write(vbTab)
            value = trx.nombreCliente : Response.Write(value) : Response.Write(vbTab)
            value = trx.MontoTechoPropio : Response.Write(value) : Response.Write(vbTab)
            value = trx.DescEstadoTechoPropio : Response.Write(value) : Response.Write(vbTab)
            Response.Write(vbCrLf)
        Next
        Response.End()
    End Sub
#End Region

#Region "       Venta Detalle                       "
    Protected Sub egvSeparacionVenta_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles egvSeparacionVenta.PageIndexChanging
        separaciones = Session("separacionesLista")
        If Not separaciones Is Nothing Then
            egvSeparacionVenta.DataSource = separaciones
            egvSeparacionVenta.PageIndex = e.NewPageIndex
            egvSeparacionVenta.DataBind()
            upnSeparacionVenta.Update()
        End If
    End Sub
#End Region
End Class
